﻿using LambdaToSql.FrameWork;
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Linq.Expressions;
using Newtonsoft.Json;
using System.Diagnostics;

namespace LambdaToSql.Realization.SqLite
{
    internal class Insertable<T> : LambdaToSql.Realization.Insertable<T> where T : class, new()
    {
        public Insertable(LambdaToSql.EntityModel.DbContext context) : base(context)
        {

        }

        public override string ExecuteNonQuery()
        {
            var DbHelper = this.Context.DbHelper;

            object retValue = "";
            var sql = base.GetSql(out retValue);
            sql += ";select last_insert_rowid() AS aliasName;";

            var ret = DbHelper.ExecuteScalar(sql, this.Entity.Parameters.ToArray());
            if (!string.IsNullOrEmpty(ret))
            {
                retValue = ret;
            }
            return retValue.ToString();
        }
    }
}
